package com.jcw.kqxt.exception;

import com.jcw.kqxt.result.JSONResult;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常
 */
@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(MyException.class)
    public JSONResult MyExceptionHandler(MyException e){
        return JSONResult.error(e.getMessage());
    }
    @ExceptionHandler(Exception.class)
    public JSONResult ExceptionHandler(Exception e){
        e.printStackTrace();
        return JSONResult.error("系统发生错误!");
    }
    @ExceptionHandler(NullPointerException.class)
    public JSONResult NullPointerExceptionHandle(NullPointerException e){
        e.printStackTrace();
        return JSONResult.error("发生了NPE错误!");
    }
}
